#include "model/model.h"

namespace infer {

template<typename R>
std::vector<R> BaseModel<R>::predict(const std::vector<image::Image>& images) {
  if (images.empty()) {
    throw std::runtime_error("Failed to find images doing inference");
  }

  // TODO add timestamp for benchmarking

  session_->infer(images);

  std::size_t s = images.size();
  std::vector<R> results(s);
  for (size_t i = 0; i < s; ++i) {
    results.emplace_back(postProcess(i));
  }

  return results;
}

template<typename R>
R BaseModel<R>::predict(const image::Image& image) {
  return predict(std::vector<image::Image>{image}).front();
}


template <>
det::ClassificationResult BaseModel<det::ClassificationResult>::postProcess(int index) {
  printf("postProcess No.%d output buffer", index);
  det::ClassificationResult result;
  // TODO

  return result;
}

template <>
det::DetectionResult BaseModel<det::DetectionResult>::postProcess(int index) {
  // auto& num_tensor = session_->tensors[1];
  // auto& box_tensor = session_->tensors[2];
  // auto& score_tensor = session_->tensors[3];
  // auto& class_tensor = session_->tensors[4];

  printf("postProcess No.%d output buffer", index);
  
  // TODO

  det::DetectionResult result;

  return result;
}



} // namespace infer